package org.zjx.dubbo;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

public class ConfigUtils {
    private static final Properties PROPERTIES = new Properties();

    static {
        try (InputStream input = ConfigUtils.class
                .getClassLoader()
                .getResourceAsStream("dubbo-consumer.properties")) {
            if (input == null) {
                throw new RuntimeException("未找到配置文件: dubbo-consumer.properties");
            }
            PROPERTIES.load(input);

            // 添加FastJSON序列化配置
            System.setProperty("dubbo.application.serialization", "fastjson2");
            System.setProperty("dubbo.application.serialization-security-check", "false");
        } catch (IOException e) {
            throw new RuntimeException("加载配置文件失败", e);
        }
    }

    public static String getProperty(String key) {
        return PROPERTIES.getProperty(key);
    }

    public static String getProperty(String key, String defaultValue) {
        return PROPERTIES.getProperty(key, defaultValue);
    }
}